import {
  createNewLock, deleteById,
  listAllLocksInfos, updateLockInfo,
} from '@/services/companyinfoApi';

export default {
  namespace: 'lockinfo',

  state: {
    data: {
      list: [],
      pagination: {},
    },
  },

  effects: {
    /**
     * 分页获取数据
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */

    * listAllLockInfos({payload}, {call, put}) {
      const response = yield call(listAllLocksInfos, payload);
      yield put({
        type: 'cb4listAllCompanyInfos',
        payload: response,
      });
    },

    /**
     * 新建智能锁
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    * createNewLock({payload}, {call, put}) {
      const response = yield call(createNewLock, payload);
      return response
    },

    /**
     * 删除智能锁
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *deleteById({ payload }, { call, put }) {
      const response = yield call(deleteById, payload);
      return response
    },

    /**
     * 更新智能锁
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *updateLockInfo({ payload }, { call, put }) {
      const response = yield call(updateLockInfo, payload);
      return response
    },
  },

  reducers: {
    cb4listAllCompanyInfos(state, action) {
      return {
        ...state,
        data: action.payload.data,
      };
    }

  }
}
